/* List clicked View */
function getLogInfo(id){
	var url = "getLogInfo.jsp";
	var param = {
		system_name : id
	};
	callAjax(url,param, "LOG_VIEW");
}

/* callAjax successAjax */
function successAjax(data, serviceName){
	if(serviceName == "LOG_VIEW"){
		/* Info value setting */
		$('#system_name').text(data.rows[0].system_name);
		$('#calender').text(data.rows[0].calender);
		$('#type').text(data.rows[0].type);
		$('#work1').text(data.rows[0].work);
		$('#result').text(data.rows[0].result);
		$('#important').text(data.rows[0].important);
		$('#worker').text(data.rows[0].worker);
		$('#ip_addr').text(data.rows[0].ip_addr);
	}
}

/* JqGrid Log List */
function initGrid() {
	$("#gridList").jqGrid({
		url:'getJqgridLogList.jsp',
		mtype: 'post',
		postData: {//search 값들
					sel_pw: $(".sel_pw").val(),
					txt_1: $(".txt_1").val(),
					txt_2: $(".txt_2").val(),
					txt_3: $(".txt_3").val(),
					sel_array: $(".sel_array").val(),
					sel_log: $(".sel_log").val()
				  },
		datatype: "json",
		colNames:['시스템명','기간','구분','작업','결과','중요도','작업자','원격지'],
		colModel:[
				{name:'system_name',index:'system_name', width:50,align:"right",key:true},
				{name:'calender',index:'calender', width:80,align:"left"},
				{name:'type',index:'type', width:180,align:"left"},
				{name:"work",index:'work', width:100,align:"right"},
				{name:'result',index:'result', width:50,align:"right"},
				{name:'important',index:'important', width:50,align:"right"},
				{name:'worker',index:'worker', width:50,align:"right"},
				{name:'ip_addr',index:'ip_addr', width:50,align:"right"}
			],
		rowList: [0,5,10,15,20],
		rowNum:5,
		height:240,
		autowidth : true,
		sortname: "system_name",
		sortorder: 'DESC',
		viewrecords: true,
		multiselect: true,//앞에 체크박스처리
		multikey: "",//multikey: "ctrlKey/shiftKey",
		pager: '#pager_id',
      
		onSelectRow: function(id){  //row가 선택되었을 경우
			getLogInfo(id);
		},
		loadComplete : function(data){
			pagecount = data.total;
			$("#pager").pager({ pagenumber: data.page, pagecount: pagecount, buttonClickCallback: PageClick });
        },
		loadError : function(xhr,st,err) {
			//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
		},
		emptyrecords: "데이터가 존재하지 않습니다.",
		caption:'테이블',
		jsonReader: {
			repeatitems:false
		}
	});
	$("#gridList").jqGrid('navGrid','#pager_id',{edit:false,add:false,del:false,search:true});
}

var pagecount;

$(document).ready(function(){
	initGrid();
});
PageClick = function(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#gridList").setGridParam({ postData: { pagePlug: pageclickednumber} }).trigger("reloadGrid");  // Postdata을 넘겨주고 url로 지정된 ajax 호출하고 Grid을 Relo
}